import sys
import pymysql
# from DBUtils.PersistentDB import PersistentDB
sys.path.append('/data/snmonitor')
# sys.path.append('E:\\snmonitor')
## 导入自定义的包
# from src.core.monitorApplication import ServiceInformation


# obtain MySQL connection
def msyqlInfo():
    f = open("../config/conf.cfg")
    f = f.read()
    for item in f.split():
        try:
            if 'host' in item:
                host = item.split('=', 1)[1]
            if 'port' in item:
                port = item.split('=', 1)[1]
            if 'username' in item:
                username = item.split('=', 1)[1]
            if 'password' in item:
                passwd = item.split('=', 1)[1]
            if 'dbname' in item:
                dbname = item.split('=', 1)[1]
        except Exception as e:
            print(e, "hhhh")

    db_config = {
        'host': host,
        'port': 3306,
        'user': username,
        'password': passwd,
        'database': dbname,
        'charset': 'utf8'
    }
    # print(db_config)

    conn = pymysql.connect(**db_config)
    cursor = conn.cursor()
    # cursor.execute("select * from monitor.monitor_disk")
    # data = cursor.fetchone()
    # print(data)
    # cursor.close()
    # conn.close()

    '''
    初始化MySQL连接
    '''
    return conn
    # print(connect_info)
    # return connect_info

if __name__ == '__main__':
    msyqlInfo()
